package avicit.cbb.businessclass.system.dataauth.service.api;


import avicit.cbb.businessclass.system.dataauth.domain.CbbAuthResource;
import avicit.platform6.core.rest.msg.ResponseMsg;
import avicit.platform6.core.restclient.RestClient;
import avicit.platform6.core.restclient.RestClientUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class BaseExtendAuthServiceApi {


    /**
     * 服务编码
     */
    private static final String SERVICE_CODE = "filebasicmanager";

    private static final String BASE_PATH = "/api/avicit/cbb/businessclass/system/dataauth/rest/BaseExtendAuthServiceRest";

    @Autowired
    private RestClient restClient;

    /**
     *获取权限服务的操作类型
     * @return
     */
    public Map<String, String> getOperateInfo() {
        String url = BASE_PATH + "/getOperateInfo";
        ResponseMsg<Map<String, String>> responseMsg = restClient.doPost(SERVICE_CODE, url,  new ParameterizedTypeReference<ResponseMsg<Map<String, String>>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }

    /**
     * 加载资源配置信息
     * @param orgId
     * @param sysId
     * @param targetType
     * @param targetId
     * @param authServiceId
     * @param s
     * @param lookupCode
     * @return
     */
    public CbbAuthResource getCbbAuthResource(String orgId, String sysId, String targetType, String targetId, String authServiceId, String s, String lookupCode) {
        String url = BASE_PATH + "/getCbbAuthResource";
        Map<String,Object> map = new HashMap<>();
        map.put("orgId",orgId);
        map.put("sysId",sysId);
        map.put("targetType",targetType);
        map.put("targetId",targetId);
        map.put("authServiceId",authServiceId);
        map.put("s",s);
        map.put("lookupCode",lookupCode);
        ResponseMsg<CbbAuthResource> responseMsg = restClient.doPost(SERVICE_CODE, url, map,  new ParameterizedTypeReference<ResponseMsg<CbbAuthResource>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }

    /**
     * 删除资源配置信息
     * @param orgId
     * @param sysId
     * @param targetType
     * @param targetId
     * @param authServiceId
     * @param s
     * @param authType
     */
    public void deleteCbbAuthResource(String orgId, String sysId, String targetType, String targetId, String authServiceId, String s, String authType) {
        String url = BASE_PATH + "/deleteCbbAuthResource";
        Map<String,Object> map = new HashMap<>();
        map.put("orgId",orgId);
        map.put("sysId",sysId);
        map.put("targetType",targetType);
        map.put("targetId",targetId);
        map.put("authServiceId",authServiceId);
        map.put("s",s);
        map.put("authType",authType);
        ResponseMsg responseMsg = restClient.doPost(SERVICE_CODE, url, map,  new ParameterizedTypeReference<ResponseMsg>() {
        });
    }


}
